<html>
<head>
<title>HOWTO - Calendar Component v5.1 Professional</title>
<style>

/**************** Body and tag styles ****************/

ol {
padding-left:0px;
}

.container_main {
padding:5px;
}

.javacode {
font-family:courier;
background-color:#f8f8f0;
padding:5px;
border:1px solid #c8c8c0;
color:#000088;
}


body{
font:76% Verdana,Tahoma,Arial,sans-serif;
line-height:1.4em;
text-align:center;
color:#303030;
background:#e8eaec;
}

pre{
font:100% Verdana,Tahoma,Arial,sans-serif;
}

a{
color:#467aa7;
font-weight:bold;
text-decoration:none;
background-color:inherit;
}

a:hover{color:#2a5a8a; text-decoration:none; background-color:inherit;}
a img{border:none;}

p form{margin-top:0; margin-bottom:20px;}

img.left,img.center,img.right{padding:4px; border:1px solid #a0a0a0;}
img.left{float:left; margin:0 12px 5px 0;}
img.center{display:block; margin:0 auto 5px auto;}
img.right{float:right; margin:0 0 5px 12px;}

/**************** Header and navigation styles ****************/

#container{
width:760px;
margin:20px auto;
padding:1px 0;
text-align:left;
background:#ffffff;
color:#303030;
border:2px solid #a0a0a0;
}

#header{
height:90px;
width:758px;
margin:0 1px 1px 1px;
background:#467aa7;
color:#ffffff;
}

#header h1{
padding:35px 0 0 20px;
font-size:2.4em;
background-color:inherit;
color:#ffffff;
letter-spacing:-2px;
font-weight:normal;
}

#header h2{
margin:10px 0 0 40px;
font-size:1.4em;
background-color:inherit;
color:#f0f2f4;
letter-spacing:-1px;
font-weight:normal;
}

#navigation{
height:2.2em;
line-height:2.2em;
width:758px;
margin:0 1px;
background:#578bb8;
color:#ffffff;
}

#navigation li{
float:left;
list-style-type:none;
border-right:1px solid #ffffff;
white-space:nowrap;
}

#navigation li a{
display:block;
padding:0 10px;
font-size:0.8em;
font-weight:normal;
text-transform:uppercase;
text-decoration:none;
background-color:inherit;
color: #ffffff;
}

* html #navigation a {width:2%;}

#navigation .selected,#navigation a:hover{
background:#80b0da;
color:#ffffff;
text-decoration:none;
}


#content{
float:left;
width:720px;
font-size:0.9em;
padding:20px 0 10px 20px;
}

#content h2{
display:block;
margin:0 0 16px 0;
font-size:1.7em;
font-weight:normal;
letter-spacing:-1px;
color:#505050;
background-color:inherit;
}

#content h2 a{font-weight:normal;}
#content h3{margin:0 0 5px 0; font-size:1.4em; letter-spacing:-1px;}
#content a:hover,#subcontent a:hover{text-decoration:underline;}
#content ul,#content ol{margin:0 5px 16px 35px;}
#content dl{margin:0 5px 10px 25px;}
#content dt{font-weight:bold; margin-bottom:5px;}
#content dd{margin:0 0 10px 15px;}

/**************** Sidebar styles ****************/

#subcontent{
float:right;
width:170px;
padding:20px 20px 10px 0;
line-height:1.4em;
}

#subcontent h2{
display:block;
margin:0 0 15px 0;
font-size:1.6em;
font-weight:normal;
text-align:left;
letter-spacing:-1px;
color:#505050;
background-color:inherit;
}

#subcontent p{margin:0 0 16px 0; font-size:0.9em;}

/**************** Menublock styles ****************/

.menublock{margin:0 0 20px 8px; font-size:0.9em;}
.menublock li{list-style:none; display:block; padding:2px; margin-bottom:2px;}
.menublock li a{font-weight:bold; text-decoration:none;}
.menublock li a:hover{text-decoration:none;}
.menublock li ul{margin:3px 0 3px 15px; font-size:1em; font-weight:normal;}
.menublock li ul li{margin-bottom:0;}
.menublock li ul a{font-weight:normal;}

/**************** Searchbar styles ****************/

#searchbar{margin:0 0 20px 0;}
#searchbar form fieldset{margin-left:10px; border:0 solid;}

#searchbar #s{
height:1.2em;
width:110px;
margin:0 5px 0 0;
border:1px solid #a0a0a0;
}

#searchbar #searchbutton{
width:auto;
padding:0 1px;
border:1px solid #808080;
font-size:0.9em;
text-align:center;
}

#footer{
clear:both;
width:758px;
padding:5px 0;
margin:0 1px;
font-size:10px;
color:#f0f0f0;
background:#467aa7;
}

#footer p{padding:0; margin:0; text-align:center;}
#footer a{color:#f0f0f0; background-color:inherit; font-weight:bold;}
#footer a:hover{color:#ffffff; background-color:inherit; text-decoration: underline;}

/**************** Misc classes and styles ****************/

.splitcontentleft{float:left; width:48%;}
.splitcontentright{float:right; width:48%;}
.clear{clear:both;}
.small{font-size:0.8em;}
.hide{display:none;}
.textcenter{text-align:center;}
.textright{text-align:right;}
.important{color:#f02025; background-color:inherit; font-weight:bold;}

.box{
margin:0 0 20px 0;
padding:10px;
border:1px solid #c0c0c0;
background-color:#fafbfc;
color:#505050;
line-height:1.5em;
}

.testimonials {
margin-top:3px;
margin-bottom:3px;
background-color: #fefef5;
padding:4px;border:1px solid #e0e0c0;
font-family:verdana;
font-size:13px;
color:#333333;
}


.headerstyle {
display:block;
margin:30px 0 10px 0;
padding:5px 0 5px 8px;
background:#eee url(images/gradient2.png) repeat-x;
color:#222;
border-top:1px solid #ddd;
border-right:1px solid #bbb;
border-bottom:1px solid #bbb;
border-left:1px solid #ddd;
text-decoration:none;
margin:20px 0 8px 0;
font-size:1.4em;
}

input,textarea {
border:1px solid #808080;
font-family:verdana;
font-size:13px;
}
</style>
</head>
<body>

<div id="container">

<div id="header">
<h1>Calendar Component v5.1 Professional - HowTo</h1>
<h2></h2>
</div>

<div class="container_main">

<p>Below are some java code snippets which displays various features 
of the Java Calendar package.


<ul> 
<div class=headerstyle>Basic Usage</div>
<p>
<ol>
<li> <a href="#CalendarComboboxUsage">How to use the CalendarComboBox class?</a>
<li> <a href="#CalendarComponentUsage">How to use the CalendarComponent class?</a>
<li> <a href="#CalendarDialogUsage">How to use the CalendarDialog class?</a>
<li> <a href="#CalendarTableCellEditorUsage">How to use the CalendarTableCellEditor class?</a>
</ol>

<div class=headerstyle>Customizing Colors and Rendering</div>
<p>
<ol>
<li> <a href="#CustomizingColors">How to customize the colors, fonts and images?</a>
<li> <a href="#ApplyingStyle">How to apply a style on the Calendar Skin?</a>
<li> <a href="#CustomSkinStyle">How to define a custom skin style?</a>
<li> <a href="#UseExternalSkin">How to use an external skin and how to export a skin?</a>
<li> <a href="#CustomizeCellsRendering">How to customize the cells rendering?</a>
<li> <a href="#CustomRendererProvider">How to define a custom calendar renderer provider?</a>
</ol>


<div class=headerstyle>Calendar Properties</div>
<p>
<ol>
<li> <a href="#ShowHideWeek">How to show/hide the week?</a>
<li> <a href="#ShowHideGrid">How to show/hide the grid?</a>
<li> <a href="#ShowHideExtraMonthDays">How to show/hide the extra month days?</a>
<li> <a href="#HoverEffect">How to enable/disable the hover effect?</a>
<li> <a href="#ShowHideStatusPanel">How to show/hide the status panel?</a>
<li> <a href="#FirstDayOfWeek">How to change the first day of week?</a>
<li> <a href="#MaxLettersInWeekDays">How to change the maximum number of letters used for displaying the week days names?</a>
<li> <a href="#MaxLettersInMonthsNames">How to change the maximum number of letters used for displaying the months names?</a>
<li> <a href="#InterRowsSpacing">How to set the inter rows spacing?</a>
<li> <a href="#InterColumnsSpacing">How to set the inter columns spacing?</a>
<li> <a href="#ChangingCalendarLocale">How to change the locale used by the calendar component?</a>
<li> <a href="#SetTextsForTodayAndNoneLabels">How to set the texts for Today and None Labels?</a>
<li> <a href="#AutomaticallyChangeTextsForTodayAndNoneLabelsWhenLocaleChanges">How to automatically change the texts for Today and None Labels when locale changes?</a>
</ol>

<div class=headerstyle>Calendar Information</div>
<p>
<ol>
<li> <a href="#TableCellInformation">How to get information about a table cell?</a>
<li> <a href="#HeaderCellInformation">How to get information about a header cell?</a>
<li> <a href="#WeekCellInformation">How to get information about a week cell?</a>
<li> <a href="#StatusPanelInformation">How to get information about the status panel?</a>
<li> <a href="#CalendarBackgroundInformation">How to get information about the calendar background?</a>
<li> <a href="#CurrentCalendarPart">How to get information about the current calendar part?</a>
<li> <a href="#HoveredCalendarPart">How to get information about the hovered calendar part?</a>
<li> <a href="#MonthViewCurrentDate">How to get/set the month view date?</a>
</ol>


<div class=headerstyle>Events and Listeners</div>
<p>
<ol>
<li> <a href="#DateListener">How to be automatically informed when the date selected in the CalendarComponent changes?</a>
<li> <a href="#CalendarComponentListener">How to be automatically informed when some of the calendar properties are changed?</a>
</ol>

<div class=headerstyle>Selection</div>
<p>
<ol>
<li> <a href="#ChangingSelectionModel">How to change the selection model used by the calendar component?</a>
<li> <a href="#AllowEmptySelection">How to allow or not empty selections?</a>
<li> <a href="#DisabledDates">How to specify the disabled dates?</a>
<li> <a href="#SelectionListener">How to be automatically informed when the selection of dates is changed?</a>
<li> <a href="#EnableDisableNullDates">How to enable/disable null dates?</a>
</ol>

<div class=headerstyle>Metrics</div>
<p>
<ol>
<li> <a href="#CalendarMetricsProvider">How to change the metrics provider?</a>
<li> <a href="#CustomTableCellMetrics">How to set the customize the size of table cells?</a>
<li> <a href="#CustomHeaderCellMetrics">How to set the customize the size of header cells?</a>
<li> <a href="#CustomWeekCellMetrics">How to set the customize the size of week cells?</a>
<li> <a href="#CustomStatusPanelMetrics">How to set the customize the size of status panel?</a>
</ol>

<div class=headerstyle>Default Implementation</div>
<p>
<ol>
<li> <a href="#DefaultCalendarComponentSwingSubcomponents">How to access Calendar Swing subcomponents for Default implementation?</a>
</ol>


<ol>

<pre>

<a name ="CalendarComboboxUsage"></a>
<li> <STRONG>How to use the CalendarComboBox class</STRONG>
The code below shows how to use a CalendarComboBox class: 

<div class=javacode><pre>
CalendarComboBox calendarComboBox = new CalendarComboBox();

CalendarComponent calendarComponent = calendarComboBox.getCalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.FIRST_DAY_OF_WEEK, new Integer(java.util.Calendar.MONDAY));
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleAqua());
calendarComponent.setCalendarRendererProvider(new CalendarRendererProviderRoundRect());

JFrame frame = new JFrame("Calendar Test");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(new JLabel("Enter a date:"));
panel.add(calendarComboBox);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
</pre></div>

<a name ="CalendarComponentUsage"></a>
<li> <STRONG>How to use the CalendarComponent class</STRONG>
The code below displays a simple usage of the CalendarComponent:
  
<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

JFrame frame = new JFrame("Calendar Test");
frame.getContentPane().add(calendarComponent);
frame.pack();
frame.setVisible(true);
</pre></div>

  
<a name ="CalendarDialogUsage"></a>
<li> <STRONG>How to use the CalendarDialog class</STRONG>
The code below shows how to use a CalendarDialog class: 

<div class=javacode><pre>
CalendarDialog calendarDialog = new CalendarDialog(null);
CalendarComponent calendarComponent = calendarDialog.getCalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.FIRST_DAY_OF_WEEK, new Integer(java.util.Calendar.MONDAY));
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleAqua());
calendarComponent.setCalendarRendererProvider(new CalendarRendererProviderRoundRect());
calendarDialog.getDialog().setTitle("Choose the date of the event");
calendarDialog.getDialog().pack();
calendarDialog.setVisible(true);
Date date = calendarDialog.getDate();
</pre></div>

<a name ="CalendarTableCellEditorUsage"></a>
<li> <STRONG>How to use the CalendarTableCellEditorUsage class</STRONG>
The code below shows how to use a CalendarTableCellEditorUsage class: 

<div class=javacode><pre>
class CustomTable extends JTable {
	
	public CalendarTableCellEditor calendarTableCellEditor = new CalendarTableCellEditor();
	
	public CustomTable() {
		this.setModel(new CustomTableModel());
		this.setRowHeight(20);
		TableColumnModel tableColumnModel = this.getColumnModel();
		tableColumnModel.getColumn(0).setMinWidth(100);
		tableColumnModel.getColumn(1).setMinWidth(200);
		
		final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd");
		this.setDefaultEditor(Date.class, calendarTableCellEditor);
		this.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
			protected void setValue(Object value) {
				if (value == null) {
					setText("null");
				} else {
					setText(simpleDateFormat.format((Date) value));
				}
			}
		});
	}
	
	public void updateUI() {
		super.updateUI();
		
		if (calendarTableCellEditor != null) {
			calendarTableCellEditor.updateUI();
		}
	}
}

class CustomTableModel extends AbstractTableModel {
  Vector data = new Vector();
  
  public CustomTableModel() {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(2005, Calendar.JANUARY, 12);
    data.add(new TableLine("First Event", calendar.getTime()));
    calendar.set(1989, Calendar.DECEMBER, 22);
    data.add(new TableLine("Second Event", calendar.getTime()));
    calendar.set(1995, Calendar.MARCH, 23);
    data.add(new TableLine("Third Event", calendar.getTime()));
  }

  public int getColumnCount() {
    return 2;
  }
  
  public boolean isCellEditable(int rowIndex, int columnIndex) {
    return true;
  }

  public int getRowCount() {
    return data.size();
  }
  
  public String getColumnName(int column) {
    if (column == 0) {
      return "Event Name";
    } else {
      return "Date";
    }
  }
  
  public Class getColumnClass(int columnIndex) {
    if (columnIndex == 0) {
      return String.class;
    } else {
      return Date.class;
    }
  }

  public Object getValueAt(int rowIndex, int columnIndex) {
    Object value = null;
    TableLine tableLine = (TableLine)data.elementAt(rowIndex);
    if (columnIndex == 0) {
      value = tableLine.eventName;
    } else if (columnIndex == 1) {
      value = tableLine.date;
    }
    return value;
  }
  
  public void setValueAt(Object value, int rowIndex, int columnIndex) {
    TableLine tableLine = (TableLine)data.elementAt(rowIndex);
    if (columnIndex == 0) {
      tableLine.eventName = (String)value;
    } else if (columnIndex == 1) {
      tableLine.date = (Date)value;
    }
  }
}


class TableLine {
  String eventName;
  Date date;
  
  public TableLine(String eventName, Date date) {
    this.eventName = eventName;
    this.date = date;
  }
}

CustomTable customTable = new CustomTable();

JFrame frame = new JFrame("Calendar Table Cell Editor");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(customTable);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
</pre></div>

<a name ="CustomizingColors"></a>
<li> <STRONG>How to customize the colors, fonts and images</STRONG>
All the colors, fonts and images informations are available in the CalendarSkin object.
  
The code below modifies the text color in the calendar cells:
  
<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.getCalendarSkin().setSkinProperty(CalendarSkin.CELL_TEXT_COLOR, new Color(18, 230, 100));
</pre></div>
  
Below are other available calendar skin properties from the CalendarSkin object: 
- CELL_TEXT_COLOR
- CELL_FILL_COLOR
- SELECTED_CELL_TEXT_COLOR
- SELECTED_CELL_FILL_COLOR
- EXTRA_MONTH_CELL_TEXT_COLOR
- WEEKEND_CELL_TEXT_COLOR
- TODAY_COLOR
- DISABLED_COLOR
- GRID_COLOR
- WEEK_CELL_TEXT_COLOR
- WEEK_CELL_FILL_COLOR
- HEADER_CELL_TEXT_COLOR
- HEADER_CELL_FILL_COLOR
- HOVERED_CELL_TEXT_COLOR
- HOVERED_CELL_FILL_COLOR
- STATUS_PANEL_FILL_COLOR
- STATUS_PANEL_TEXT_COLOR
- STATUS_PANEL_HOVERED_TEXT_COLOR
- CELL_FONT
- WEEKEND_CELL_FONT
- EXTRA_MONTH_CELL_FONT
- WEEK_CELL_FONT
- HEADER_CELL_FONT
- STATUS_PANEL_FONT
- BACKGROUND_IMAGE

<a name ="ApplyingStyle"></a>
<li> <STRONG>How to apply a style on the Calendar Skin</STRONG>
The code below shows how to apply a style on the Calendar Skin:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleAqua());
</pre></div>

The skins are available in the java package com.imagine.component.calendar.skins. Also it can be used external skins. 
Please see <a href =" api/index.html">API documentation</a> for more details. 

<a name ="CustomSkinStyle"></a>

<li> <STRONG>How to define a custom skin style</STRONG>
The user can also define very easy a skin style:

<div class=javacode><pre>
class CalendarSkinStyleCustom extends CalendarSkinStyle {

  public void applyStyle(CalendarSkin calendarSkin)  throws CalendarPropertyException {
    calendarSkin.setSkinProperty(CalendarSkin.CELL_TEXT_COLOR, new Color(101, 101, 31));
    calendarSkin.setSkinProperty(CalendarSkin.CELL_FILL_COLOR, new Color(189, 209, 173));
    calendarSkin.setSkinProperty(CalendarSkin.EXTRA_MONTH_CELL_TEXT_COLOR, new Color(128, 128, 128));
    calendarSkin.setSkinProperty(CalendarSkin.WEEKEND_CELL_TEXT_COLOR, new Color(54, 54, 16));
    
    calendarSkin.setSkinProperty(CalendarSkin.TODAY_COLOR, new Color(255, 0, 0));
    calendarSkin.setSkinProperty(CalendarSkin.DISABLED_COLOR, new Color(255, 0, 0));
    calendarSkin.setSkinProperty(CalendarSkin.GRID_COLOR, new Color(134, 151, 130));
    
    calendarSkin.setSkinProperty(CalendarSkin.SELECTED_CELL_FILL_COLOR, new Color(82, 107, 61));
    calendarSkin.setSkinProperty(CalendarSkin.SELECTED_CELL_TEXT_COLOR, new Color(255, 255, 255));
    
    calendarSkin.setSkinProperty(CalendarSkin.HOVERED_CELL_FILL_COLOR, new Color(82, 107, 61));
    calendarSkin.setSkinProperty(CalendarSkin.HOVERED_CELL_TEXT_COLOR, new Color(255, 255, 255));
    
    calendarSkin.setSkinProperty(CalendarSkin.HEADER_CELL_TEXT_COLOR, new Color(212, 208, 200));
    calendarSkin.setSkinProperty(CalendarSkin.HEADER_CELL_FILL_COLOR, new Color(128, 128, 128));
    
    calendarSkin.setSkinProperty(CalendarSkin.WEEK_CELL_TEXT_COLOR, new Color(212, 208, 200));
    calendarSkin.setSkinProperty(CalendarSkin.WEEK_CELL_FILL_COLOR, new Color(128, 128, 128));
    
    calendarSkin.setSkinProperty(CalendarSkin.STATUS_PANEL_TEXT_COLOR, new Color(101, 101, 31));
    calendarSkin.setSkinProperty(CalendarSkin.STATUS_PANEL_HOVERED_TEXT_COLOR, new Color(82, 107, 61));
    calendarSkin.setSkinProperty(CalendarSkin.STATUS_PANEL_FILL_COLOR, new Color(189, 209, 173));
    
    // Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
    calendarSkin.setSkinProperty(CalendarSkin.CELL_FONT, null);
    // Set the font for the specified property to be the default component font but with the specified style.
    getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.CELL_FONT_WRAPPER).setStyle(Font.PLAIN);
    
    // Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
    calendarSkin.setSkinProperty(CalendarSkin.EXTRA_MONTH_CELL_FONT, null);
    // Set the font for the specified property to be the default component font but with the specified style.
    getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.EXTRA_MONTH_CELL_FONT_WRAPPER).setStyle(Font.ITALIC);
    
    // Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
    calendarSkin.setSkinProperty(CalendarSkin.WEEKEND_CELL_FONT, null);
    // Set the font for the specified property to be the default component font but with the specified style.
    getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.WEEKEND_CELL_FONT_WRAPPER).setStyle(Font.ITALIC |Font.BOLD);
    
    // Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
    calendarSkin.setSkinProperty(CalendarSkin.HEADER_CELL_FONT, null);
    // Set the font for the specified property to be the default component font but with the specified style.
    getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.HEADER_FONT_WRAPPER).setStyle(Font.PLAIN);
    
    // Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
    calendarSkin.setSkinProperty(CalendarSkin.WEEK_CELL_FONT, null);
    // Set the font for the specified property to be the default component font but with the specified style.
    getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.WEEK_FONT_WRAPPER).setStyle(Font.PLAIN);
    
    // Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
    calendarSkin.setSkinProperty(CalendarSkin.STATUS_PANEL_FONT, null);
    // Set the font for the specified property to be the default component font but with the specified style.
    getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.STATUS_PANEL_FONT_WRAPPER).setStyle(Font.BOLD);
    
    calendarSkin.setSkinProperty(CalendarSkin.BACKGROUND_IMAGE, null);
  }
  
  public String getName() {
    return "Custom";
  }
}

CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleCustom());
</pre></div>

<a name ="UseExternalSkin"></a>
<li> <STRONG>How to use an external skin</STRONG>
The code below shows how to use an external skin: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleExternalFile(new File("./skins/skin01.skin")));

calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleExternalURL(new URL("http://www.calendarcomponent.com/skins/skin01.skin")));

CalendarSkinStyleExternalFile.exportSkin(calendarComponent.getCalendarSkin(), new File("./skins/test.skin"));
</pre></div>

<a name ="CustomizeCellsRendering"></a>
<li> <STRONG>How to customize the cells rendering</STRONG>
All the rendering is performed using the CalendarRendererProvider object.

The code below changes from a calendar renderer provider to another: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarRendererProvider(new CalendarRendererProviderRoundRect());
</pre></div>

The calendar renderers are available in the java package com.imagine.component.calendar.renderers. 
Please see <a href =" api/index.html">API documentation</a> for more details. 

<a name ="CustomRendererProvider"></a>
<li> <STRONG>How to define a custom calendar renderer provider</STRONG>

The code below defines a custom calendar renderer provider which handle the drawing for some days differently from normal drawing: 

<div class=javacode><pre>
class CalendarTableCellRendererCustom implements CalendarTableCellRenderer {

  public void paint(Graphics g, CalendarComponent calendarComponent, CalendarTableCellInfo calendarTableCellInfo) {
  	// If the calendar has a background renderer then this will actually paint the calendar background. 
  	// So this table cell renderer will no longer paint the cell background in this case. 
    if (!calendarComponent.getCalendarRendererProvider().hasBackgroundRenderer()) {
      g.setColor(calendarComponent.getCalendarSkin().getColorSkinProperty(CalendarSkin.CELL_FILL_COLOR));
      g.fillRect(0, 0, calendarTableCellInfo.getWidth(), calendarTableCellInfo.getHeight());
    }
    
    g.setColor(new Color(255, 0, 0));
    g.fillOval(0, 0, calendarTableCellInfo.getWidth(), calendarTableCellInfo.getHeight());
    
    g.setColor(new Color(0, 0, 255));
    drawCenteredString(g, calendarTableCellInfo.getWidth(), calendarTableCellInfo.getHeight(), (String)calendarTableCellInfo.getValue());
	if (calendarTableCellInfo.isDisabled()) {
		g.setColor(calendarComponent.getCalendarSkin().getColorSkinProperty(CalendarSkin.DISABLED_COLOR));
		int count = 3;
		g.drawLine(count, count, calendarTableCellInfo.getWidth() - count, calendarTableCellInfo.getHeight() - count);
		g.drawLine(count, calendarTableCellInfo.getHeight() - count, calendarTableCellInfo.getWidth() - count, count);
	}
  }

  public String toString() {
    return "Custom";
  }
  
  public static void drawCenteredString(Graphics g, int width, int height, String text) {
    FontMetrics fontMetrics = g.getFontMetrics();
    int currentWidth = fontMetrics.stringWidth(text);
    int currentHeight = fontMetrics.getAscent() - 3;
    
    int x = (width - currentWidth) / 2;
    if (x < 0) {
      x = 0;
    }
    int y = (height - currentHeight) / 2;
    if (y < 0) {
      y = 0;
    }
    y = height - y;
    
    g.drawString(text, x, y);
  }
}  

class CalendarRendererProviderCustom extends CalendarRendererProviderDefault {

  CalendarTableCellRendererCustom calendarTableCellRendererCustom = new CalendarTableCellRendererCustom();

  public CalendarTableCellRenderer getTableCellRenderer(CalendarTableCellInfo calendarTableCellInfo) {
    if (calendarTableCellInfo.getMonthType() == CalendarMonthType.CURRENT_MONTH && calendarTableCellInfo.getDayOfMonth() == 12 || calendarTableCellInfo.getDayOfMonth() == 21) {
      return calendarTableCellRendererCustom;
    }
    
    return super.getTableCellRenderer(calendarTableCellInfo);
  }
  
  
  public String getName() {
    return "Custom";
  }
}


CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarRendererProvider(new CalendarRendererProviderCustom());
</pre></div>

<a name ="FirstDayOfWeek"></a>
<li> <STRONG>How to change the first day of week</STRONG>
The code below changes the first day of week to Tuesday: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.FIRST_DAY_OF_WEEK, new Integer(java.util.Calendar.TUESDAY));
</pre></div>

<a name ="ShowHideWeek"></a>
<li> <STRONG>How to show/hide the week</STRONG>
The code below shows how to show/hide the week: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
//    show week
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_WEEK, new Boolean(true));
//    hide week
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_WEEK, new Boolean(false));
</pre></div>

<a name ="ShowHideGrid"></a>
<li> <STRONG>How to show/hide the grid</STRONG>
The code below shows how to show/hide the grid: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
//    show grid
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_GRID, new Boolean(true));
//    hide grid
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_GRID, new Boolean(false));
</pre></div>

<a name ="ShowHideExtraMonthDays"></a>
<li> <STRONG>How to show/hide the extra month days</STRONG>
The code below shows how to show/hide the extra month days: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
//    show extra month days
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_EXTRA_MONTH_DAYS, new Boolean(true));
//    hide extra month days
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_EXTRA_MONTH_DAYS, new Boolean(false));
</pre></div>

<a name ="HoverEffect"></a>
<li> <STRONG>How to enable/disable the hover effect</STRONG>
The code below shows how to enable/disable the hover effect: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
//enable hover effect
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_HOVER, new Boolean(true));
//disable hover effect
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_HOVER, new Boolean(false));
</pre></div>

<a name ="MaxLettersInWeekDays"></a>
<li> <STRONG>How to change the maximum number of letters used for displaying the week days names</STRONG>
The code below changes the maximum number of letters used for displaying the week days names: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.MAX_WEEK_DAYS_NAMES_LENGTH, new Integer(2));
</pre></div>

<a name ="MaxLettersInMonthsNames"></a>
<li> <STRONG>How to change the maximum number of letters used for displaying the months names</STRONG>
The code below changes the maximum number of letters used for displaying the months names: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.MAX_MONTHS_NAMES_LENGTH, new Integer(5));
</pre></div>

<a name ="InterRowsSpacing"></a>
<li> <STRONG>How to set the inter rows spacing?</STRONG>
The code below shows how to set the inter rows spacing: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.INTER_ROWS_SPACING, new Integer(2));
</pre></div>

<a name ="InterColumnsSpacing"></a>
<li> <STRONG>How to set the inter columns spacing?</STRONG>
The code below shows how to set the inter columns spacing: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.INTER_COLUMNS_SPACING, new Integer(2));
</pre></div>

<a name ="DateListener"></a>
<li> <STRONG>How to be automatically informed when the date selected in the CalendarComponent changes</STRONG>
The code below shows how to add a date listener: 

<div class=javacode><pre>

CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.addDateListener(new DateListener() {
  public void dateChanged(Date date) {
    // some java code here
  }
});
</pre></div>

<a name ="CalendarComponentListener"></a>
<li> <STRONG>How to be automatically informed when some of the calendar properties are changed</STRONG>
The code below shows how to create a CalendarComponentListener: 


<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.addCalendarComponentListener(new CalendarComponentListener() {
  public void processCalendarEvent(CalendarEvent calendarEvent) {
    if (calendarEvent instanceof CalendarEventFirstDayOfWeekChanged) {
      CalendarEventFirstDayOfWeekChanged calendarEventFirstDayOfWeekChanged = (CalendarEventFirstDayOfWeekChanged)calendarEvent;
      System.out.println("First day of week:" + calendarEventFirstDayOfWeekChanged.getFirstDayOfWeek());
      // some java code here
    } else if (calendarEvent instanceof CalendarEventMaxMonthsNamesLengthChanged) {
      CalendarEventMaxMonthsNamesLengthChanged calendarEventMaxMonthsNamesLengthChanged = (CalendarEventMaxMonthsNamesLengthChanged)calendarEvent;
      System.out.println("Max Months Names Length:" + calendarEventMaxMonthsNamesLengthChanged.getMaxMonthsNamesLength());
      // other java code here
    }
  }

  public Class[] getEventsListened() {
    return new Class[] {
        CalendarEventFirstDayOfWeekChanged.class,
        CalendarEventMaxMonthsNamesLengthChanged.class
    };
  }
});
</pre></div>

<a name ="ChangingCalendarLocale"></a>
<li> <STRONG>How to change the locale used by the calendar component</STRONG>
The code below shows how to change the calendar locale: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.LOCALE, Locale.FRANCE);
</pre></div>

<a name ="ChangingSelectionModel"></a>
<li> <STRONG>How to change the selection model used by the calendar component</STRONG>
The code below shows how to change the selection model used: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarSelectionModel(new CalendarSelectionModelSingleIntervalSelection());
</pre></div>



<a name ="AllowEmptySelection"></a>
<li> <STRONG>How to allow or not empty selections</STRONG>
The code below shows how to allow or not empty selections: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
//  allow empty selection
calendarComponent.getCalendarSelectionModel().setEmptySelectionAllowed(true);
//  not allow empty selection
calendarComponent.getCalendarSelectionModel().setEmptySelectionAllowed(false);
</pre></div>



<a name ="DisabledDates"></a>
<li> <STRONG>How to specify the disabled dates</STRONG>
The code below shows how to specify the disabled dates: 

<div class=javacode><pre>
class CalendarSelectionModelCustom extends CalendarSelectionModelMultipleIntervalSelection {

  private GregorianCalendar calendar = new GregorianCalendar();
  
  public boolean isDateDisabled(Date date) {
    calendar.setTime(date);
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    return (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY);
  }
  
  public String getName() {
    return "Custom";
  }
}

CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarSelectionModel(new CalendarSelectionModelCustom());
</pre></div>


<a name ="SelectionListener"></a>
<li> <STRONG>How to be automatically informed when the selection of dates is changed</STRONG>
The code below shows how to register a selection listener: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.getCalendarSelectionModel().addCalendarSelectionListener(new CalendarSelectionListener() {

	public void selectionChanged(CalendarSelectionModel calendarSelectionModel) {
		Date[] selectedDates = calendarSelectionModel.getSelectedDates();
		
		// Process the selected dates.
	}

});
</pre></div>

<a name ="ShowHideStatusPanel"></a>
<li> <STRONG>How to show/hide the status panel</STRONG>
The code below shows how to show/hide the status panel: 

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
//    show status panel
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_STATUS_PANEL, new Boolean(true));
//    hide status panel
calendarComponent.setCalendarProperty(CalendarComponent.SHOW_STATUS_PANEL, new Boolean(false));
</pre></div>

<a name ="EnableDisableNullDates"></a>
<li> <STRONG>How to enable/disable null dates</STRONG>
The code below shows how to enable/disable null dates. When null dates are disabled the "None" label will no longer appear on the status panel. The user can select a null date by clicking on the "None" label or by pressing BACKSPACE when the calendar table has focus.

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
//    enable null dates
calendarComponent.getCalendarSelectionModel().setEmptySelectionAllowed(true);
//    disable null dates 
calendarComponent.getCalendarSelectionModel().setEmptySelectionAllowed(false);
</pre></div>

<a name ="SetTextsForTodayAndNoneLabels"></a>
<li> <STRONG>How to set the texts for Today and None Labels</STRONG>
The code below shows how to set the texts for Today and None Labels. The text for Today label can contain between the '{' and '}' characters a pattern in the format accepted by the java.text.SimpleDateFormat class.

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
//    set text for today label
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Hoy: {MM.dd.yyyy}");
//    set text for none label
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Ninguno");
</pre></div>

<a name ="AutomaticallyChangeTextsForTodayAndNoneLabelsWhenLocaleChanges"></a>
<li> <STRONG>How to automatically change the texts for Today and None Labels when locale changes</STRONG>
The code below shows how to automatically change the texts for Today and None Labels when locale changes: 

<div class=javacode><pre>
final CalendarComponent calendarComponent = new CalendarComponent();

calendarComponent.addCalendarComponentListener(new CalendarComponentListener() {
  
  public Class[] getEventsListened() {
	  return new Class[]{CalendarEventLocaleChanged.class};
  }
  
  public void processCalendarEvent(CalendarEvent calendarEvent) {
	  Locale locale = calendarComponent.getLocaleCalendarProperty(CalendarComponent.LOCALE);
	  if (locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) {
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Today: {MM.dd.yyyy}");
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "None");
	  } else if (locale.getLanguage().equals(Locale.GERMAN.getLanguage())) {
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Heute: {MM.dd.yyyy}");
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Kein");
	  } else if (locale.getLanguage().equals(Locale.FRENCH.getLanguage())) {
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Aujourd''hui: {MM.dd.yyyy}");
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Aucun");
	  } else if (locale.getLanguage().equals(Locale.ITALIAN.getLanguage())) {
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Oggi: {MM.dd.yyyy}");
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Nessuno");
	  } else if (locale.getLanguage().equals(new Locale("es", "", "").getLanguage())) {
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Hoy: {MM.dd.yyyy}");
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Ninguno");
	  } else if (locale.getLanguage().equals(new Locale("ro", "", "").getLanguage())) {
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Astazi: {MM.dd.yyyy}");
		  calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Nimic");
	  }
  }
  
});
</pre></div>

<a name ="TableCellInformation"></a>
<li> <STRONG>How to get information about a table cell</STRONG>
The code below shows how to get information about a table cell:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

int row = 0;
int column = 3;
CalendarTableCellInfo calendarTableCellInfo = calendarComponent.getCalendarView().getMonthView().getTableCellInfo(row, column);
</pre></div>

<a name ="HeaderCellInformation"></a>
<li> <STRONG>How to get information about a header cell</STRONG>
The code below shows how to get information about a header cell:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

int column = 4;
CalendarHeaderCellInfo calendarHeaderCellInfo = calendarComponent.getCalendarView().getMonthView().getHeaderCellInfo(column);
</pre></div>

<a name ="WeekCellInformation"></a>
<li> <STRONG>How to get information about a week cell</STRONG>
The code below shows how to get information about a week cell:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

int row = 4;
CalendarWeekCellInfo calendarWeekCellInfo = calendarComponent.getCalendarView().getMonthView().getWeekCellInfo(row);
</pre></div>

<a name ="StatusPanelInformation"></a>
<li> <STRONG>How to get information about the status panel</STRONG>
The code below shows how to get information about the status panel:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

CalendarStatusPanelInfo calendarStatusPanelInfo = calendarComponent.getCalendarView().getMonthView().getCalendarStatusPanelInfo();
</pre></div>

<a name ="CalendarBackgroundInformation"></a>
<li> <STRONG>How to get information about the calendar background</STRONG>
The code below shows how to get information about the calendar background:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

CalendarBackgroundInfo calendarBackgroundInfo = calendarComponent.getCalendarView().getMonthView().getCalendarBackgroundInfo();
</pre></div>

<a name ="CurrentCalendarPart"></a>
<li> <STRONG>How to get information about the current calendar part</STRONG>
The code below shows how to get information about the current calendar part:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

CalendarPartInfo calendarPartInfo = calendarComponent.getCalendarView().getMonthView().getCurrentCalendarPartInfo();
</pre></div>

<a name ="HoveredCalendarPart"></a>
<li> <STRONG>How to get information about the hovered calendar part</STRONG>
The code below shows how to get information about the hovered calendar part:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

CalendarPartInfo calendarPartInfo = calendarComponent.getCalendarView().getMonthView().getHoveredCalendarPartInfo();
</pre></div>

<a name ="MonthViewCurrentDate"></a>
<li> <STRONG>How to get/set the month view date</STRONG>
The code below shows how to get/set the month view date:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

// Get the month view current date. 
// The current date is the date from which the key operations are started. 
Date currentDate = calendarComponent.getCalendarView().getMonthView().getMonthViewCurrentDate();


// Set the date displayed by the month view.
// This become the date from which the key operations are started.
// This is not usually the calendar date. The calendar may display a month but it can have selected dates in other months.
GregorianCalendar calendar = new GregorianCalendar();
calendar.set(Calendar.YEAR, 1990);
calendar.set(Calendar.MONTH, Calendar.AUGUST);
calendar.set(Calendar.DAY_OF_MONTH, 15);

calendarComponent.getCalendarView().getMonthView().setMonthViewCurrentDate(calendar.getTime());
</pre></div>

<a name ="CalendarMetricsProvider"></a>
<li> <STRONG>How to change the metrics provider</STRONG>
The code below shows how to change the metrics provider:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderTight());
</pre></div>


<a name ="CustomTableCellMetrics"></a>
<li> <STRONG>How to set the customize the size of table cells</STRONG>
The code below show howto customize the size of table cells:

<div class=javacode><pre>
class CalendarMetricsProviderCustomTable extends CalendarMetricsProviderDefault {

  CalendarTableCellMetricsCustom calendarTableCellMetricsCustom = new CalendarTableCellMetricsCustom();

  public CalendarTableCellMetrics getTableCellMetrics(CalendarTableCellInfo calendarTableCellInfo) {
    return calendarTableCellMetricsCustom;
  }
  
  public String getName() {
    return "Custom";
  }
}

class CalendarTableCellMetricsCustom implements CalendarTableCellMetrics {
	Dimension dimension = new Dimension(0, 0);
	
	/**
	 * @inheritDoc
	 */
  public Dimension getPreferredSize(CalendarComponent calendarComponent, CalendarTableCellInfo calendarTableCellInfo) {
  	FontMetrics fontMetrics = getFontMetrics(calendarComponent, calendarTableCellInfo);
  	
  	dimension.width = fontMetrics.stringWidth( (String)calendarTableCellInfo.getValue() + "  ") + 20;
  	dimension.height = fontMetrics.getAscent() + 15;
  	
  	return dimension;
	}
  
	private FontMetrics getFontMetrics(CalendarComponent calendarComponent, CalendarTableCellInfo calendarTableCellInfo) {
	  Font font = calendarComponent.getFont();
	  int dayOfWeek = calendarTableCellInfo.getDayOfWeek();
	  CalendarMonthType calendarMonthType = calendarTableCellInfo.getMonthType();
	  boolean isFromWeekend = (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY);
	  if (calendarMonthType != CalendarMonthType.CURRENT_MONTH) {
	    font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.EXTRA_MONTH_CELL_FONT); 
	  } else if (isFromWeekend) {
	    font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.WEEKEND_CELL_FONT);
	  } else {
	    font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.CELL_FONT);
	  }
	  return calendarComponent.getFontMetrics(font);
	}

  public String toString() {
    return "Custom";
  }
}  

CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderCustomTable());
</pre></div>

<a name ="CustomHeaderCellMetrics"></a>
<li> <STRONG>How to set the customize the size of header cells</STRONG>


<div class=javacode><pre>
class CalendarMetricsProviderCustomHeader extends CalendarMetricsProviderDefault {

  CalendarHeaderCellMetricsCustom calendarHeaderCellMetricsCustom = new CalendarHeaderCellMetricsCustom();

  public CalendarHeaderCellMetrics getHeaderCellMetrics(CalendarHeaderCellInfo calendarHeaderCellInfo) {
    return calendarHeaderCellMetricsCustom;
  }
  
  public String getName() {
    return "Custom";
  }
}

class CalendarHeaderCellMetricsCustom implements CalendarHeaderCellMetrics {
	Dimension dimension = new Dimension(0, 0);
	
	/**
	 * @inheritDoc
	 */
  public Dimension getPreferredSize(CalendarComponent calendarComponent, CalendarHeaderCellInfo calendarHeaderCellInfo) {
  	FontMetrics fontMetrics = getFontMetrics(calendarComponent, calendarHeaderCellInfo);
  	
  	dimension.width = fontMetrics.stringWidth( (String)calendarHeaderCellInfo.getValue() + " ") + 14;
  	dimension.height = fontMetrics.getAscent() + 14;
  	
  	return dimension;
	}
  
	private FontMetrics getFontMetrics(CalendarComponent calendarComponent, CalendarHeaderCellInfo calendarHeaderCellInfo) {
  	Font font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.HEADER_CELL_FONT);
	  return calendarComponent.getFontMetrics(font);
	}

  public String toString() {
    return "Custom";
  }
}  

CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderCustomHeader());
</pre></div>

<a name ="CustomWeekCellMetrics"></a>
<li> <STRONG>How to set the customize the size of week cells</STRONG>


<div class=javacode><pre>
class CalendarMetricsProviderCustomWeek extends CalendarMetricsProviderDefault {

  CalendarWeekCellMetricsCustom calendarWeekCellMetricsCustom = new CalendarWeekCellMetricsCustom();


  public CalendarWeekCellMetrics getWeekCellMetrics(CalendarWeekCellInfo calendarWeekCellInfo) {
    return calendarWeekCellMetricsCustom;
  }
  
  public String getName() {
    return "Custom";
  }
}

class CalendarWeekCellMetricsCustom implements CalendarWeekCellMetrics {
	Dimension dimension = new Dimension(0, 0);
	
	/**
	 * @inheritDoc
	 */
  public Dimension getPreferredSize(CalendarComponent calendarComponent, CalendarWeekCellInfo calendarWeekCellInfo) {
  	FontMetrics fontMetrics = getFontMetrics(calendarComponent, calendarWeekCellInfo);
  	
  	dimension.width = fontMetrics.stringWidth( "AA") + 14;
  	dimension.height = fontMetrics.getAscent() + 14;
  	
  	return dimension;
	}
	
	private FontMetrics getFontMetrics(CalendarComponent calendarComponent, CalendarWeekCellInfo calendarWeekCellInfo) {
  	Font font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.WEEK_CELL_FONT);
	  return calendarComponent.getFontMetrics(font);
	}

  public String toString() {
    return "Custom";
  }
}  

CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderCustomWeek());
</pre></div>

<a name ="CustomStatusPanelMetrics"></a>
<li> <STRONG>How to set the customize the size of status panel</STRONG>


<div class=javacode><pre>
class CalendarMetricsProviderCustomStatusPanel extends CalendarMetricsProviderDefault {

  CalendarStatusPanelMetricsCustom calendarStatusPanelMetricsCustom = new CalendarStatusPanelMetricsCustom();

  
  public CalendarStatusPanelMetrics getStatusPanelMetrics(CalendarStatusPanelInfo calendarStatusPanelInfo) {
    return calendarStatusPanelMetricsCustom;
  }
  
  public String getName() {
    return "Custom";
  }
}

class CalendarStatusPanelMetricsCustom implements CalendarStatusPanelMetrics {
	
	Dimension dimension = new Dimension(0, 0);
	
	/**
	 * @inheritDoc
	 */
  public Dimension getPreferredSize(CalendarComponent calendarComponent, CalendarStatusPanelInfo calendarStatusPanelInfo) {
  	FontMetrics fontMetrics = getFontMetrics(calendarComponent, calendarStatusPanelInfo);
  	
  	dimension.width = fontMetrics.stringWidth(calendarStatusPanelInfo.getTodayLabel() + " " + calendarStatusPanelInfo.getNoneLabel() + "  ") + 14;
  	dimension.height = fontMetrics.getAscent() + 14;
  	
  	return dimension;
	}
  
	private FontMetrics getFontMetrics(CalendarComponent calendarComponent, CalendarStatusPanelInfo calendarStatusPanelInfo) {
  	Font font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.STATUS_PANEL_FONT);
	  return calendarComponent.getFontMetrics(font);
	}
  
	
  public String toString() {
    return "Custom";
  }
}  

CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderCustomStatusPanel());
</pre></div>

<a name ="DefaultCalendarComponentSwingSubcomponents"></a>
<li> <STRONG>How to access Calendar Swing subcomponents for Default implementation</STRONG>
The code below shows how to access Calendar Swing subcomponents for Default implementation:

<div class=javacode><pre>
CalendarComponent calendarComponent = new CalendarComponent();

CalendarNavigationController calendarNavigationController = calendarComponent.getCalendarView().getNavigationController();
if (calendarNavigationController instanceof CalendarNavigationControllerDefault) {
	CalendarNavigationControllerDefault calendarNavigationControllerDefault = ((CalendarNavigationControllerDefault)calendarNavigationController);
	
	JComboBox monthComboBox = calendarNavigationControllerDefault.getMonthComboBox();
	JTextField yearTextField = calendarNavigationControllerDefault.getYearTextField();
	JButton yearButtonUp = calendarNavigationControllerDefault.getYearButtonUp();
	JButton yearButtonDown = calendarNavigationControllerDefault.getYearButtonDown();
}

CalendarComboBox calendarComboBox = new CalendarComboBox();
CalendarComboBoxView calendarComboBoxView = calendarComboBox.getCalendarComboBoxView();
if (calendarComboBoxView instanceof CalendarComboBoxViewDefault) {
	CalendarComboBoxViewDefault calendarComboBoxViewDefault = ((CalendarComboBoxViewDefault)calendarComboBoxView);
	
	JTextField textField = calendarComboBoxViewDefault.getTextField();
	JButton buttonDown = calendarComboBoxViewDefault.getButtonDown();
}
</pre></div>


</pre>

</ol>
</div>
</body>

</html>
